/**
 *
 * Copyright Pact Lab of H.I.T.
 *
 * Designed and Implemented by Grid Researching Group, 
 * Pact Lab, Harbin
 * 
 * This Project is part of the national 973 Project:
 * Internet Based Virtual Computing Environment
 *
 * http://pact518.hit.edu.cn
 * 
 * Author:       Meteor <meteorlxk@gmail.com> 
 * Copyright:    pact518 
 * Version:      1.0
 * Created:      2008-11-18 
 * LastModified: 2008-11-18
 */
package edu.hit.pact.pgse.crawler.util;

import java.util.*;

import edu.hit.pact.pgse.util.Md5Sum;

public class DuplicateUrlFilter {
	
	private Set<Long> duplicateUrlSet;
	
	public DuplicateUrlFilter() {
		duplicateUrlSet = new HashSet<Long>();
	}
	
	public synchronized boolean contains(String url) {
		Long key = Md5Sum.getMd5LongSum(url);
		return !duplicateUrlSet.add(key);
	}
	
	public synchronized boolean remove(String url) {
		Long key = Md5Sum.getMd5LongSum(url);
		return duplicateUrlSet.remove(key);
	}
	
	public synchronized boolean removeAll(List<String> urls) {
		List<Long> keys = new ArrayList<Long>();
		for (String url : urls) {
			keys.add(Md5Sum.getMd5LongSum(url));
		}//end for
		return duplicateUrlSet.removeAll(keys);
	}
	public synchronized void clear(){
		duplicateUrlSet.clear();
	} 
	
}
